package com.tvunetworks.center.user.util;

import com.tvunetworks.center.common.constant.LocalConstant;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: tvucc-user
 * @description: UserUtil
 * @author lebronchen
 * @create: 2019-03-14 18:55
 **/
public class UserUtil {

    /**
     * 根据设备类型，查询出数据库中in的字符串
     * @param types types
     * @param extType  Ext,YouTube,SMPTE2022
     * @return String
     */
    public static String packageDeviceTypesToString(List<String> types, String extType){
        if (types == null || types.size() == 0) {
            return null;
        }
        List<String> typeList = new ArrayList<>(types);
        boolean existExt = types.contains(LocalConstant.DeviceType.Ext);
        if (existExt) {
            String[] exts = extType.split(",");
            for (String ext : exts) {
                if (LocalConstant.DeviceType.Ext.equalsIgnoreCase(ext)) {
                    continue;
                }
                typeList.add(ext);
            }
        }
        return typeList.toString().replaceAll(", ", "','").replace("[", "('").replace("]", "')");
    }

    /**
     *
     * @param extType extType
     * @return String
     */
    public static String packageExtTypesToString(String extType){
        List<String> typeList = new ArrayList<>();
        String[] exts = extType.split(",");
        for (String ext : exts) {
            typeList.add(ext);
        }
        return typeList.toString().replaceAll(", ", "','").replace("[", "('").replace("]", "')");
    }

    /**
     *
     * @param args args
     */
    public static void  main(String[] args){
        String s = UserUtil.packageDeviceTypesToString(Arrays.asList(new String[]{"Ext", "T"}), "Ext,YouTube,SMPTE2022");
        System.out.println(s);
    }

}
